package com.haichang.demomybatis.controller;

import org.springframework.web.bind.annotation.RestController;

import com.haichang.demomybatis.entity.Good;
import com.haichang.demomybatis.mapper.GoodMapper;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;


/*
 * Controller负责网页跳转链接
 */
@RestController
@CrossOrigin
public class GoodController {

    @Autowired
    private GoodMapper goodMapper;

    @GetMapping("/good")
    public List<Good> query(){

        List<Good> good = goodMapper.selectList(null);
        // System.out.println(goods);
        return good;
    }
    
    @PostMapping("/good")
    public String save(Good good) {
        int i =goodMapper.insert(good);    
        if(i>0){
            return "插入成功";
        }else{

            return "插入失败";
        }
    }
    
}
